/*获得对象 
	target可接受this,id,name
	flag可接受null,'id','name'
	为name时，可能返回数组
*/
	function getTargetTwo(target,flag){
		var obj;
		if(typeof(target)=="object"){
			obj = target;
		}
		if(typeof(target)=="string"){
			if("name"==flag){
				obj = document.getElementsByName(target);
			}else{
				obj = document.getElementById(target);
			}
		}
		return obj;
	}

	/*获得对象 
	target可接受this,id,name
	*/
	function getTarget(idOrNameOrThis){
		var obj = getTargetTwo(idOrNameOrThis,null);
		if(obj!=null){
			return obj;
		}
		obj = getTargetTwo(idOrNameOrThis,'id');
		if(obj!=null){
			return obj;
		}
		obj = getTargetTwo(idOrNameOrThis,'name');
		if(obj!=null){
			if(typeof(obj.length)!=="undefined"){
				return obj[0];
			}else if(typeof(obj)=="object"){
				return obj;
			}
		}
	}

	/*
	idOrNameOrThis：该控件被选中，则其他控件不可用 对于select 控件 选中第一位则后边不可编辑
	elseId：被控制的控件id eg: a,s,ef,, etc
	*/
	function disabledElseElements(idOrNameOrThis,elseId){
		var obj = getTarget(idOrNameOrThis);
		var flag = true;
		if(obj.type=="radio" || obj.type=="checkbox"){
			if(obj.checked==true){
			}else{
				flag = false;
			}	
		}else if(obj.type=="select-one"){
			if(obj.selectedIndex==0){
			}else{
				flag = false;
			}
		}
		if(elseId.indexOf(",")>0){
			var elseIds = elseId.split(",");
			for(var i = 0 ; i< elseIds.length;i++){
				if(elseIds[i]!=""){
					getTarget(elseIds[i]).disabled = flag;
					getTarget(elseIds[i]).readOnly = flag;
				}
			}
		}else{
			getTarget(elseId).disabled = flag;
		}
	}
	
	
	/*
	idOrNameOrThis：该控件被选中，则控件可用 对于select 控件 选中第一位则后边不可编辑
	elseId：被控制的控件id eg: a,s,ef,, etc
	*/
	function disabledcol(idOrNameOrThis,elseId){
		var obj = getTarget(idOrNameOrThis);
		var flag = false;
		if(obj.type=="radio" || obj.type=="checkbox"){
			if(obj.checked==true){
			}else{
				flag = true;
			}	
		}else if(obj.type=="select-one"){
			if(obj.selectedIndex==0){
			}else{
				flag = true;
			}
		}
		if(elseId.indexOf(",")>0){
			var elseIds = elseId.split(",");
			for(var i = 0 ; i< elseIds.length;i++){
				if(elseIds[i]!=""){
					getTarget(elseIds[i]).disabled = flag;
				}
			}
		}else{
			getTarget(elseId).disabled = flag;
		}
	}
	
//全选
function checkAll(checkGroup)
{
  var names=document.getElementsByName(checkGroup);
  var len=names.length;
  if(len>0)
  {
   var i=0;
   for(i=0;i<len;i++)
   names[i].checked=true;
    
  }
}
//全不选
function checkAllNo(checkGroup)
{
 var names=document.getElementsByName(checkGroup);
 var len=names.length;
 if(len>0)
  {
    var i=0;
    for(i=0;i<len;i++)
    names[i].checked=false;
  }
}
//计算复选框被选中的数量
function calculate_checkbox(tagName){
	var checks = document.getElementsByName(tagName);
	var max = 0 ; 
	if(checks==null){
		return null;
	}else if(typeof(checks.length) !== 'undefined'){
		for(var i=0;i<checks.length;i++){
			if(checks[i].checked==true){
				max = max + 1;
			}
		}
	}else if(typeof(checks)=="object"){
		if(checks.checked==true)
			max = max + 1;
	}
	return max;
}